package com.example.sprintbootarithmetic.DataStructure.arithmetic_array;

public class Demo {
    public static void main(String[] args) {
        // 0���������ӣ�1�����к����ӣ�2���������
        int[][] demo = new int[11][11];// ��ά����
        demo[8][8] = 2;
        demo[4][6] = 1;
        demo[7][7] = 2;
        int[][] demos = array(demo);
        int[][] demo2 = new int[11][11];
        for (int i = 1; i < demos.length; i++) {
            demo2[demos[i][0]][demos[i][1]] = demos[i][2];
        }
        for (int row[] : demo2) {
            for (int s : row) {
                System.out.print(s + "\t");
            }
            System.out.println("\n");
        }
    }

    public static int[][] array(int[][] dem) {
        int sum = 0;
        for (int i = 0; i < dem.length; i++) {
            for (int j = 0; j < dem.length; j++) {
                if (dem[i][j] != 0) {
                    sum++;
                }
            }
        }
        int[][] a = new int[sum + 1][3];
        a[0][0] = 11;
        a[0][1] = 11;
        a[0][2] = sum;
        int count = 0;// ϡ�������еĵڼ���ֵ
        for (int i = 0; i < 11; i++) {
            for (int j = 0; j < 11; j++) {
                if (dem[i][j] != 0) {
                    count++;// ��¼�ڼ���count��ֵ����:[0][0],[0][1],[0][2],[1][1],[1][2]
                    a[count][0] = i;
                    a[count][1] = j;
                    a[count][2] = dem[i][j];
                }
            }
        }
        return a;
    }
}
